package servlet;

import bean.User;
import util.Page;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

public class UserServlet extends BaseBackServlet {
    @Override
    public String add(HttpServletRequest request, HttpServletResponse response, Page page) {
        return null;
    }

    @Override
    public String delete(HttpServletRequest request, HttpServletResponse respone, Page page) {
        int id = Integer.parseInt(request.getParameter("uid"));
        userDAO.delete(id);
        String str = "@admin_user_list";
        return str;
    }

    @Override
    public String edit(HttpServletRequest request, HttpServletResponse response, Page page) {
        return null;
    }

    @Override
    public String update(HttpServletRequest request, HttpServletResponse response, Page page) {
        return null;
    }

    @Override
    public String list(HttpServletRequest request, HttpServletResponse response, Page page) {
        int start = page.getStart();
        int count = page.getCount();
        int total = userDAO.getTotal();
//        System.out.println(start+"--"+count+"--"+total);
        page.setTotal(total);
        List<User> users = userDAO.list(start,count);
        request.setAttribute("users", users);
        request.setAttribute("page", page);
        return "jsp/admin/listUser.jsp";
    }
}
